/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#ifndef __LOCK_H__
#define __LOCK_H__

#include <NoCopy.h>

namespace liba
{
namespace threads
{


class LockObject
{
	friend class Lock;
protected:
	virtual void lock_object()const=0;
	virtual void unlock_object()const=0;
	virtual ~LockObject()
	{}
};

class Lock : private Nocopy
{
	const LockObject & lock_object;
public:
	explicit Lock(const LockObject & lock_object)
		:	lock_object( lock_object )
	{
		lock_object.lock_object();
	}
	~Lock()
	{
		lock_object.unlock_object();
	}
};

class Mutex : public LockObject, private Nocopy
{
	class Impl;
	Impl * impl;

	virtual void lock_object()const;
	virtual void unlock_object()const;
public:
	Mutex();
	virtual ~Mutex();
};

} //namespace threads
} //namespace liba
using namespace liba;

#endif //__LOCK_H__